package com.atguigu.springcloud.controller;

import com.atguigu.commonutils.R;
import com.atguigu.springcloud.entity.Payment;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

@RestController
@Slf4j
@RequestMapping("/consumer")
public class OrderController {

    public static final String PAYMENT_URL = "http://CLOUD-PROVIDER-SERVICE";

    @Autowired
    private RestTemplate restTemplate;

    @GetMapping("create")
    public R create(Payment payment){

        return restTemplate.postForObject(PAYMENT_URL + "/payment/create",payment,R.class);
    }

    @GetMapping("payment/get/{id}")
    public R getPaymentById(@PathVariable Long id){
        return restTemplate.getForObject(PAYMENT_URL + "/payment/getPaymentById/"+id,R.class);
    }

}
